/// @tags: K-D Tree
#include <algorithm>
#include <cctype>
#include <cstdio>

namespace BlueQuantum {

int const N = 2e5 + 5, K = 2;
double const alpha = 0.75;

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

struct Point {
  int x[K];
  inline bool operator<=(Point const &rhs) const {
    return x[0] <= rhs.x[0] && x[1] <= rhs.x[1];
  }
  inline bool operator>=(Point const &rhs) const {
    return x[0] >= rhs.x[0] && x[1] >= rhs.x[1];
  }
  inline void operator<<(Point const &rhs) {
    for (int i = 0; i < K; ++i) x[i] = std::min(x[i], rhs.x[i]);
  }
  inline void operator>>(Point const &rhs) {
    for (int i = 0; i < K; ++i) x[i] = std::max(x[i], rhs.x[i]);
  }
};

struct ValPoint : Point {
  int val;
};

struct Node {
  int siz, sum, ls, rs;
  Point max, min;
  ValPoint p;
} tr[N];

int n, cnt, top, dim;
int rev[N];

inline bool cmp(int const lhs, int const rhs) {
  return tr[lhs].p.x[dim] < tr[rhs].p.x[dim];
}

inline bool operator<(Point const lhs, Point const &rhs) {
  return lhs.x[dim] < rhs.x[dim];
}

inline void pushup(int x) {
  tr[x].siz = 1;
  tr[x].sum = tr[x].p.val;
  tr[x].max = tr[x].min = tr[x].p;
  if (tr[x].ls) {
    tr[x].siz += tr[tr[x].ls].siz;
    tr[x].sum += tr[tr[x].ls].sum;
    tr[x].max >> tr[tr[x].ls].max;
    tr[x].min << tr[tr[x].ls].min;
  }
  if (tr[x].rs) {
    tr[x].siz += tr[tr[x].rs].siz;
    tr[x].sum += tr[tr[x].rs].sum;
    tr[x].max >> tr[tr[x].rs].max;
    tr[x].min << tr[tr[x].rs].min;
  }
}

inline void del(int x) {
  if (!x) return;
  rev[++top] = x;
  del(tr[x].ls), del(tr[x].rs);
  tr[x].ls = tr[x].rs = 0;
}

inline void build(int &x, int l, int r, int k) {
  if (l > r) return;
  int mid = (l + r) >> 1;
  dim = k;
  std::nth_element(rev + l, rev + mid, rev + r + 1, cmp);
  x = rev[mid];
  build(tr[x].ls, l, mid - 1, !k);
  build(tr[x].rs, mid + 1, r, !k);
  pushup(x);
}

inline void rebuild(int &x, int k) {
  rev[top = 1] = cnt;  // 把插入的点塞进去
  del(x);
  build(x, 1, top, k);
}

void insert(int &x, int k, ValPoint const &hl) {
  if (!x) {
    tr[x = cnt].p = hl;
    tr[cnt].max = hl, tr[cnt].min = hl;
    tr[cnt].siz = 1, tr[cnt].sum = hl.val;
    return;
  }
  dim = k;
  if (hl < tr[x].p) {
    if (tr[tr[x].ls].siz + 1 > alpha * tr[x].siz) rebuild(x, k);
    else
      insert(tr[x].ls, k ^ 1, hl);
  } else {
    if (tr[tr[x].rs].siz + 1 > alpha * tr[x].siz) rebuild(x, k);
    else
      insert(tr[x].rs, k ^ 1, hl);
  }
  pushup(x);
}

int query(int x, Point const lhs, Point const rhs) {
  if (!x) return 0;
  if (lhs <= tr[x].min && tr[x].max <= rhs) return tr[x].sum;
  int res = 0;
  if (lhs <= tr[x].p && tr[x].p <= rhs) res += tr[x].p.val;
  if (tr[tr[x].ls].max >= lhs) res += query(tr[x].ls, lhs, rhs);
  if (tr[tr[x].rs].min <= rhs) res += query(tr[x].rs, lhs, rhs);
  return res;
}

inline int main() {
  read(n);
  ValPoint a, b;
  int ans = 0, rt = 0;
  for (int typ; true;) {
    read(typ);
    switch (typ) {
      case 1:
        read(a.x[0]) ^= ans, read(a.x[1]) ^= ans, read(a.val) ^= ans;
        tr[++cnt].p = a;
        insert(rt, 0, a);
        break;
      case 2:
        read(a.x[0]) ^= ans, read(a.x[1]) ^= ans;
        read(b.x[0]) ^= ans, read(b.x[1]) ^= ans;
        printf("%d\n", ans = query(rt, a, b));
        break;
      case 3:
        return 0;
    }
  }
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4148 简单题.in", "r", stdin);
  freopen("P4148 简单题.out", "w", stdout);
#endif
#endif

  return BlueQuantum::main();
}